package cn.kgc.watch.web;

import cn.kgc.watch.entity.Address;
import cn.kgc.watch.entity.ResultInfo;
import cn.kgc.watch.service.AddressService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
@RestController
/**
 * 地址表
 */
@CrossOrigin
public class AddressController {
    @Resource
    private AddressService addressService;
    @GetMapping("findAddress")
    public List<Address> findAddress(Integer userId){
        return this.addressService.findByUserId(userId);
    }


    @GetMapping("userAddress")
    public ResultInfo userAddress(Integer id){
        return new ResultInfo(200,"成功",this.addressService.findById(id));
    }
    @DeleteMapping("removeAddress")
    public ResultInfo removeAddress(Integer id){
        this.addressService.remove(id);
        return new ResultInfo(200,"成功");
    }

    @PostMapping("addAddress")
    private ResultInfo addAddress(@RequestBody Address address){
        this.addressService.add(address);
        return new ResultInfo(200,"成功");
    }

    @PutMapping("modifyAddress")
    private ResultInfo modifyAddress(@RequestBody Address address){
        this.addressService.modify(address);
        return new ResultInfo(200,"成功");
    }
}
